package com.yjy.shmily.account;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import com.orhanobut.hawk.Hawk;

public class AccountHelper {
    private String token;
    @SuppressLint("StaticFieldLeak")
    private static AccountHelper instances;

    public static void init() {
        if (instances == null)
            instances = new AccountHelper();
        else {
            instances.token = Hawk.get("token");
        }
    }

    public static boolean isLogin() {
        return !TextUtils.isEmpty(getToken());
    }

    public static String getToken() {
        return Hawk.get("token") == null ? "" : Hawk.get("token");
    }

    public static boolean updateToken(String token) {
        if (token == null || token.equals(""))
            return false;
        instances.token = token;
        return Hawk.put("token", token);
    }

    private static void clearUserCache() {
        instances.token = null;
        Hawk.delete("token");
    }
}
